//
//  BBSystemManger.m
//  BlockBrowser
//
//  Created by Mac on 2018/4/8.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "BBSystemManger.h"

@implementation BBSystemManger
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self beginNetWork];
        [self sendRegisterAwardRequest];
    }
    return self;
}
+ (BBSystemManger *)manger{
    static BBSystemManger * shared = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shared = [BBSystemManger new];
    });
    return shared;
}
- (void)beginNetWork{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",severHeader,@"/api/user/getSystemParam"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypeGet
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 
                                                 self.originDic = responseObject;
                                                 self.news_line = responseObject[@"news_line"];
                                                 self.news_font_size = responseObject[@"news_font_size"];
                                                 NSLog(@"json= %@",self.originDic.mj_JSONString);
                                                 self.share_rule_news = [NSMutableArray new];
                                                 self.share_rule_qrcode = [NSMutableArray new];
                                                 NSArray * share_rule_news   =responseObject[@"share_rule_news"];
                                                 for (NSDictionary * modelDic in share_rule_news) {
                                                     BBRuleModel * model =  [BBRuleModel mj_objectWithKeyValues:modelDic];
                                                     [self.share_rule_news addObject:model];
                                                 }
                                                 NSArray * share_rule_qrcode   =responseObject[@"share_rule_qrcode"];
                                                 for (NSDictionary * modelDic in share_rule_qrcode) {
                                                     BBRuleModel * model =  [BBRuleModel mj_objectWithKeyValues:modelDic];
                                                     [self.share_rule_qrcode addObject:model];
                                                 }
                                                 self.candyName = responseObject[@"short_name"];
                                                 self.share_font_size = responseObject[@"share_font_size"];

                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                                     [self beginNetWork];
                                                 });

                                             }];
}
- (void)sendRegisterAwardRequest{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:@"1" forKey:@"type"];
    NSString * url = [NSString stringWithFormat:@"%@%@",severHeader,@"/api/user/getRegisterAward"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypeGet
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 
                                                 self.registerAward = [responseObject[@"data"] description];
                                                 self.share = [responseObject[@"share"] description];
                                                 self.invite_bg = [responseObject[@"invite_bg"] description];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                                     [self sendRegisterAwardRequest];
                                                 });
                                                 
                                             }];
}
@end
